import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

/**
 * @Author zzz
 * @Date 2022/3/31 4:37 下午
 * @Version 1.0
 */
public class input {
    public static TreeNode getTree2() {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        if (s.length() == 2) {
            //输入数据很少
            TreeNode root = null;
        }
        String[] ss = s.substring(1, s.length() - 1).split(",");
        TreeNode root = new TreeNode(Integer.parseInt(ss[0]));
        Queue<TreeNode> queue = new LinkedList<>();
        queue.add(root);
        int index = 1;
        while (index < ss.length) {
            TreeNode temp = queue.poll();
            if (temp == null) {
                index += 2;
            } else {
                if (ss[index++].equals("null")) {
                    temp.left = null;
                } else {
                    temp.left = new TreeNode(Integer.parseInt(ss[index - 1]));
                }
                queue.add(temp.left);
                if (ss[index++].equals("null")) {
                    temp.right = null;
                } else {
                    temp.right = new TreeNode(Integer.parseInt(ss[index - 1]));
                }
                queue.add(temp.right);
            }
        }
        return root;
    }
    public static TreeNode getTree(String s){
        if (s.length() == 2) {
            //输入数据很少
            TreeNode root = null;
        }
        String[] ss = s.substring(1, s.length() - 1).split(",");
        TreeNode[] nodes = new TreeNode[ss.length];
        for (int i = 0; i < ss.length; i++) {
            if (!ss[i].equals("null"))
                nodes[i] = new TreeNode(Integer.parseInt(ss[i]));
            else
                nodes[i] = null;
        }
        for (int i = 0; i * 2 + 2 < ss.length; i++) {
            if (nodes[i]!=null){
                nodes[i].left = nodes[2 * i +1];
                nodes[i].right = nodes[2 * i +2];
            }
        }
        return nodes[0];
    }
    public static ListNode getListNode(String s){
        String[] ss = s.substring(1, s.length() - 1).split(",");
        ListNode[] nodes = new ListNode[ss.length];
        for (int i = 0; i < nodes.length; i++) {
            nodes[i] = new ListNode(Integer.parseInt(ss[i]));
        }
        for (int i = 0; i < nodes.length - 1; i++) {
            nodes[i].next = nodes[i+1];
        }
        return nodes[0];
    }
}
